package com.imooc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hello")
public class HelloController6 {
    @Autowired
    private GirlProperties girlProperties;
    @RequestMapping(value = "/say/{id}",method = RequestMethod.GET)
    public String say6(@PathVariable("id") Integer id){
        return "id:" + id;
    }
//上面用的PathVariable，id就是对应里面的id,访问方式是http://localhost:8082/hello/say/23
    @RequestMapping(value = "/say2",method = RequestMethod.GET)
    public String say61(@RequestParam("id") Integer myId){
        return "id:" + myId;
    }
//下面用的RequestParam，myId就是自己取的名字，访问方式是http://localhost:8082/hello/say2?id=23
//如果不传参数的话http://localhost:8082/hello/say2?id=结果就是id:null

//    @RequestMapping(value = "/say3",method = RequestMethod.GET)
    @GetMapping(value = "/say3")
    public String say62(@RequestParam(value = "id",required = false,defaultValue = "0") Integer myId){
        return "id:" + myId;
    }
    //required = false,defaultValue = "0"意思是required可以不传值，defaultValue默认值是0
    //这里defaultValue的默认值是0，不能直接写0，需要加个双引号“0”才行
    //如果不传值的话http://localhost:8082/hello/say3也不会报错，结果是id:0
//@GetMapping(value = "/say3")是为了简化配置
// 他的效果和@RequestMapping(value = "/say3",method = RequestMethod.GET)一模一样

}